#include "Fifteenth.h"
#include <iostream>
#include <stdio.h>

int main() {
	vector< char > firstpos;
	int k;
	for( int i = 0; i < 16; ++i ) {
		cin >> k;
		firstpos.push_back( k );
	}
	Fifth fif;
	vector< int > sol = fif.GetSolution( firstpos );
	vector< Sost >* gr = fif.GetGraph()->GetNodesLs();
	for( int i = 0; i < sol.size(); ++i ) {
		for( int k = 0; k < 16; k++ ) {
			cout << ( int )( *gr )[ sol[i] ].GetVal( k ) << " ";
		}
		cout << endl << "then" << endl;
	}
	cout << "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0" << endl;
	return 0;
}